package com.bai.qf2201.controller;

import com.bai.qf2201.po.Car;
import com.bai.qf2201.po.City;
import com.bai.qf2201.service.Impl.carServiceImpl;
import com.bai.qf2201.service.Impl.cityServiceImpl;
import com.bai.qf2201.vo.CarAndCity;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.lang.invoke.MethodHandle;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class cityController {

    @Autowired
    private cityServiceImpl cityService;
    @Autowired
    private carServiceImpl carService;


    @ResponseBody
    @RequestMapping("/getCity")
    public List<City> getCity(int pid){
        List<City> byId = cityService.findById(pid);
        return byId;
    }
    @ResponseBody
    @RequestMapping("/getCity2")
    public List<City> getCity2(int getid,int backid ){
        City byId = cityService.findById2(getid);
        City byId2 = cityService.findById2(backid);

        List<City> citys=new ArrayList<>();
        citys.add(byId);
        citys.add(byId2);

        System.out.println(citys);
        return citys;
    }
    @ResponseBody
    @RequestMapping("/getCity3")
    public CarAndCity getCity3(int getid, int backid, int cid){
        Car car= carService.findOneById(cid);
        City byId = cityService.findById2(getid);
        City byId2 = cityService.findById2(backid);

        CarAndCity cac = new CarAndCity();
        cac.setGetCity(byId);
        cac.setBackCity(byId2);
        cac.setCar(car);

        System.out.println(cac);
        return cac;
    }
}
